#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    // 创建子进程
    pid_t id = fork();
    if (id == 0)
    {
        // 子进程
        std::cout << "I am child process" << std::endl;
        sleep(5);
        std::cout << "execl" << std::endl;
        execl("/usr/bin/ls", "-l", "-a", NULL);
        exit(0);
    }
    // 父进程
    int status = 0;
    int ret = waitpid(id, &status, 0);
    if (ret > 0)
    {
        std::cout << "wait child " << id << " sucess, sig: " << ((status>>7)&0x7f) << std::endl;
    }
    return 0;
}